var CLIENT_WIDTH  = -1; // Window Width
var CLIENT_HEIGHT = -1; // Window Height
var openwin_handle = 0; // window handler

function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj == obj.offsetParent);
		return {x:curleft,y:curtop};
	}
	return null;
}

function getDivXLocation(divId) {
	var obj = document.getElementById(divId);
	if(obj) {
		var loc = findPos(obj);
		return (document.all)?parseInt(loc.x):parseInt(obj.offsetLeft);
	}
	return -1;
}
function getDivYLocation(divId) {
	var obj = document.getElementById(divId);
	var loc = findPos(obj);
	if(obj) {
		return (document.all)?parseInt(obj.pixelTop):parseInt(obj.offsetTop);
	}
	return -1;
}

function getSeed() {
	var today=new Date();
	var seed = (today.getTime()*84363) % 8630;
	return (seed/(934320))*1000;
}

function rand() {
	return Math.floor(getSeed()*203183);
}

function browserLocation(newloc) {
	parent.window.location= newloc;
}

function isNumber(a) {
	return typeof a == 'number' && isFinite(a);
}

function SetClientVariables() {
	if(document.all)
		{
			CLIENT_HEIGHT = document.body.clientHeight;
			CLIENT_WIDTH = document.body.clientWidth;
		}
		else
			{
				CLIENT_WIDTH = window.innerWidth;
				CLIENT_HEIGHT = window.innerHeight;
			}
		}
		
		function OpenCustomWin(loc,width,height)
		{
			SetClientVariables();
			
			if(width >= CLIENT_WIDTH)
				width = CLIENT_WIDTH-40;
			//	if(height >= CLIENT_HEIGHT)
			//		height = CLIENT_HEIGHT-40;
			
			Nleft = ((CLIENT_WIDTH-width)/2);
			Ntop = 20;//((CLIENT_HEIGHT-height)/2);
			
			if(document.all)
				width += 10;
			var options = "WIDTH=" + width + ",HEIGHT=" + height + ",TOP=" + Ntop + ",LEFT=" + Nleft + ",SCROLLBARS=NO,TOOLBAR=NO,MENUBAR=NO,RESIZABLE=NO,STATUS=NO,DIRECTORIES=NO";
			openwin_handle = window.open(loc, "NONAME",options);
		}
		
		function OpenCustomScrollWin(loc,width,height)
		{
			SetClientVariables();
			
			if(width >= CLIENT_WIDTH)
				width = CLIENT_WIDTH-40;
			if(height >= CLIENT_HEIGHT)
				height = CLIENT_HEIGHT-40;
			
			Nleft = ((CLIENT_WIDTH-width)/2);
			Ntop = 20;//((CLIENT_HEIGHT-height)/2);
			
			if(document.all)
				width += 10;
			var options = "WIDTH=" + width + ",HEIGHT=" + height + ",TOP=" + Ntop + ",LEFT=" + Nleft + ",TOOLBAR=NO,MENUBAR=NO,RESIZABLE=NO,STATUS=NO,DIRECTORIES=NO,SCROLLBARS=YES";
			openwin_handle = window.open(loc, "NONAME",options);
		}
		
		function CheckValidEmail(email)
		{
			if(email.length<5)
				return false;
			if(email.indexOf('@')<=0)
				return false;
			if(email.indexOf('.')<=0)
				return false;
			// could check that there is something between the @ and the . and after that, there are at least 2 after the last .
			// but hey...this is my last day and I'm not goign to push things too much!
			return true;
		}
		function getScrollXY() {
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
				scrOfY = window.pageYOffset;
				scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function removeAllNodes(container) {
	if (container.hasChildNodes())
		{
			while (container.childNodes.length >= 1)
				{
					container.removeChild(container.firstChild);
				}
			}
		}
function showBlock(pstrID) {
	var myDiv = document.getElementById('d' + pstrID);
	if (myDiv){
		myDiv.style.display = 'block'; // SHOW this block
	}
}
function hideBlock(pstrID) {
	var myDiv = document.getElementById('d' + pstrID);
	if (myDiv){
		myDiv.style.display = 'none';
	}
}
function toggleBlock(pstrID) {
	var myDiv = document.getElementById('d' + pstrID);
	if (myDiv) {
		if (myDiv.style.display == 'none') {
			showBlock(pstrID);
			return true;
		} else {
		hideBlock(pstrID);
		return false;
		}
	}
}